﻿
	import cn.eminia.A2.utils.uArray;
	import cn.eminia.A2.utils.uMC;
	import cn.eminia.A2.utils.uRegPoint;
	import flash.geom.Point;
	import gs.*; 
import mx.transitions.easing.*;
import mx.utils.Delegate;
import mx.utils.ObjectCopy;
/**
 * ...
 * @author wangjun
 */
class cn.eminia.A2.utils.uTween 
{
	
	public function uTween(a, b, c, d) {
		if (a == null) {
			throw new Error("大错，TwAll 没有 MC");
			return;
		}
		switch (b.toLowerCase()) {
		case 'listlee' :
			TwListLee(a, b, c, d);
			break;
		case 'list' :
			TwList(a, b, c, d);
			break;    
		case 'roundbar' :
			Tw070(a, b, c, d);
			break;
		case 'doback' :
			Tw071(a, b, c, d);
			break;
		default :
			throw new Error("指定错");
		}
	}
	function TwListLee(arr, b, c, d) {
		if (arr.constructor == MovieClip) {
			var arr = cn.eminia.A2.Util.orderBy('|', arr);
		}
		if (uArray.compareArray(c, [0, 1])) {
			for (var i = 0; i<arr.length; i++) {
				var aa = arr[i];
				aa._visible = true;
				aa._alpha = 0;
				TweenLite.to(aa, .6, {delay:.1*i, _alpha:100, _y:'-10'});
			}
		} else {
		}
	}
	function TwList(arr, b, c, d) {
		if (arr.constructor == MovieClip) {
			var arr = cn.eminia.A2.Util.orderBy('|', arr);
		}
		if (uArray.compareArray(c, [0, 1])) {
			for (var i = 0; i<arr.length; i++) {
				var aa = arr[i];
				aa._visible = true;
				aa._alpha = 0;
				TweenLite.to(aa, .6, {delay:.1*i, _alpha:100});
			}
		} else {
		}
	}
	public static function blur(mc:MovieClip,size:Number) {
			
		var size:Number = (size != null)?size:10;
		TweenMax.to(mc, 1, {
			blurFilter: { blurX:15,blurY:size }
		});
		
	}
	public static function blurBack(mc:MovieClip) {
		
		TweenMax.to(mc, 1, {
			blurFilter: { blurX:0,blurY:0 }
		});	
		
	}
	public static function pannel0(aa:MovieClip) {
		if (aa._xscale2 != null) { 
			TweenMax.to(aa, .1, {_xscale2:100, _yscale2:100, blurFilter:{blurX:0, blurY:0}});
		}
		aa._visible = true;
		aa._alpha = 100;
	}
	public static function pannel(a:MovieClip,  c:Array, d:Object,e:Point) {
		var obj:Object = { };
		obj.d = d;
		if (uArray.compareArray(c, [1, 0])) {
			/*TweenLite.to(a, .4, {_alpha:0, onCompleteScope:a, onComplete:function () {
			a._visible = false;
			}});*/
			if (a._xscale2 == null) {
				uRegPoint.init(a,e);
			}
			TweenMax.to(a, .2, { _xscale2:90, _yscale2:90, blurFilter: { blurX:5, blurY:5 }} );
			
			d.scope = (d.scope == null) ? a : d.scope;
				
			TweenLite.to(a, .4, { overwrite:false, _alpha:0, 
				onCompleteScope:obj, 
				onComplete:function () {	
					a._visible = false;
					
					trace('pannel::d.scope 1-0 = '+d.scope); 
					if (d.onComplete != null) {
						Delegate.create(d.scope, d.onComplete)();						
					} 
				}
			}); 
				
		} else {
			//a.gotoAndPlay(1) 
			a._visible = true;
			a._alpha = 0;
			/*TweenLite.to(a, .4, {_alpha:100});*/
			if (a._xscale2 == null) {
				uRegPoint.init(a,e);
			}
			a._xscale2 = 90;
			a._yscale2 = 90;
			TweenMax.to(a, .2, {_xscale2:100, _yscale2:100, blurFilter:{blurX:0, blurY:0}});
			d.scope = (d.scope == null) ? a : d.scope;
			TweenMax.to(a, .4, { overwrite:false, _alpha:100,
				onCompleteScope:obj, 
				onComplete:function () {	 
					
					trace('pannel::d.scope 0-1 = '+d.scope); 
					trace('pannel::d.scope 0-1 onComplete = '+d.onComplete); 
					if (d.onComplete != null) {
						Delegate.create(d.scope, d.onComplete)();						
					} 
				}
			});
		}
	}
	public static function pannel_bezier(a:MovieClip,  c:Array, d:Object,e:Point) {
		var obj:Object = { };
		obj.d = d;
		if (uArray.compareArray(c, [1, 0])) {
			/*TweenLite.to(a, .4, {_alpha:0, onCompleteScope:a, onComplete:function () {
			a._visible = false;
			}});*/
			if (a._xscale2 == null) {
				uRegPoint.init(a,e);
			}
			TweenMax.to(a, .2, { 
							blurFilter: { blurX:5, blurY:5 }
			} );
			
			var endPos:Point = d.endPos; 
			
			d.scope = (d.scope == null) ? a : d.scope;
			
			TweenMax.to(a, 1.2, {
							overwrite:false,
							_xscale2:10,
							_yscale2:10,
							overwrite:false ,
							bezier:[ { _x:62, _y:369 }, { _x: endPos.x, _y:endPos.y } ], 
							onCompleteScope:obj, 
							onComplete:function () {	
								a._visible = false;
								
								trace('pannel::d.scope 1-0 = '+d.scope); 
								if (d.onComplete != null) {
									Delegate.create(d.scope, d.onComplete)();						
								} 
							}
			});  
			TweenMax.to(a, .3, {
							overwrite:false,
							delay:1,
							_alpha: 0
			}); 
				
		} else {
			//a.gotoAndPlay(1) 
			a._visible = true;
			a._alpha = 0;
			if (a._xscale2 == null) {
				uRegPoint.init(a,e);
			}
			
			var sttPos:Point = d.sttPos;
			a._x2 = sttPos.x;
			a._y2 = sttPos.y;
			
			a._xscale2 = 10;
			a._yscale2 = 10; 
			
			
			TweenLite.to(a, .6, { 
							_alpha:100 
			} );
			
			TweenMax.to(a, 1, {
							overwrite:false, 
							delay:.1, 
							blurFilter: { blurX:0, blurY:0} 
			}); 
			
			d.scope = (d.scope == null) ? a : d.scope;
			
			TweenMax.to(a, 1.2, { 
							overwrite:false, 
							delay:.1,
							_xscale2:100, 
							_yscale2:100, 
							bezier:[ { _x:62, _y:369 }, { _x:231, _y:115 } ], 
							
							onCompleteScope:obj, 
							onComplete:function () {	 
								
								trace('pannel::d.scope 0-1 = '+d.scope); 
								trace('pannel::d.scope 0-1 onComplete = '+d.onComplete); 
								if (d.onComplete != null) {
									Delegate.create(d.scope, d.onComplete)();						
								} 
							}
			});
		}
	}
	public static function fadeOut(mc:MovieClip, vars:Object) { 
		if (vars == null) {
			pannel_NoBlur(mc,[1,0]);
		} else {
			var obj:Object = new Object();
			obj = ObjectCopy.copy(vars); 
			pannel_NoBlur(mc,[1,0],obj);
		}
	}
	public static function fadeIn(mc:MovieClip,vars:Object) {
		if (vars == null) {
			pannel_NoBlur(mc,[0,1]);
		} else {
			var obj:Object = new Object();
			//obj = ObjectCopy.copy(vars); 
			//pannel_NoBlur(mc,[0,1],obj);
			pannel_NoBlur(mc,[0,1],vars);
		} 
	}
	public static function pannel_NoBlur(mc:MovieClip, c:Array, d:Object) {
		var obj:Object = { };
		obj.d = d;
		if (uArray.compareArray(c, [1, 0])) {
			if (d.onComplete != null) {
				d.scope = (d.scope == null) ? mc : d.scope;
				TweenLite.to(mc, .4, { _alpha:0, 
					onCompleteScope:obj, 
					onComplete:function () {
						Delegate.create(d.scope, d.onComplete)(); 
						mc._visible = false;
					}
				});
				return;
			}else{
				TweenLite.to(mc, .4, { _alpha:0, 
					onCompleteScope:obj, 
					onComplete:function () {
						mc._visible = false;
					}
				});
			}
		} else { 
			mc._visible = true;
			mc._alpha = 0;
			if (d.onComplete != null) {
				TweenLite.to(mc, .4, { _alpha:100,
					onCompleteScope:obj, 
					onComplete:function () {
						Delegate.create(d.scope, d.onComplete)(); 
						mc._visible = false;
					}
				} );
			}else {
				TweenLite.to(mc, .4, { _alpha:100 } );				
			}
		}
	}
	public static function formLeft(target,vars:Object) {
		if (target.constructor == MovieClip) {
			var arr:Array = uMC.orderBy('|', target); 
			trace("arr = "+ arr )
			form(arr, [0, 1], vars);
		}else if(target.constructor == Array) {
			form(target, [0, 1], vars);
		}
	}
	public static function formRight(target,vars:Object) {
		if (target.constructor == MovieClip) {
			var arr:Array = uMC.orderBy('|', target); 
			trace("arr = " + arr );
			form(arr, [1, 0], vars);
		}else if(target.constructor == Array) {
			form(target, [1, 0], vars);
		}
	}
	public static function form(arr:Array, type:Array, vars:Object) { 
		var delayOffset:Number =  (vars.delayOffset != null)?vars.delayOffset:0;
		if (uArray.compareArray(type, [0, 1])) 
		{
			for (var i = 0; i < arr.length; i++) 
			{
				var ooo = arr[i];
				ooo._alpha = 0;
				ooo._x -= 20;
				TweenLite.to(arr[i], .6, 
				{ 
					delay:delayOffset+.15 * i, 
					_x:ooo._x + 20, 
					_alpha:100
				});
			}
		} else {
			for (var i = 0; i < arr.length; i++) 
			{
				var ooo = arr[i];
				ooo._alpha = 0;
				ooo._x += 20;
				TweenLite.to(arr[i], .6, 
				{ 
					delay:delayOffset+.15 * i, 
					_x:ooo._x - 20, 
					_alpha:100
				});
			}
		}
	}
	function Tw070(a:MovieClip, b, c, d) {
		if (d.dir == '-') {
			if (a.mm.constructor == MovieClip) {
				//
				TweenLite.to(a.mm, c, {_width:0});
				a.onEnterFrame = function() {
					trace(this.mm._width);
					trace(this.rr._x);
					this.rr._x = this.mm._width+this.mm._x-1;
				};
			} else if (a.bar.constructor == MovieClip) {
				/*if (a.msk == null) {
				throw new Error('大错  没有 MC msk ');
				} */
				TweenLite.to(a.bar, c, { _x:a.bar._x - a.bar._width, 
								onComplete:Delegate.create(d.onCompleteScope, function () {
											d.onComplete();
								}), 
								ease:None.easeIn});
			}
		}
	}
	function Tw071(a:MovieClip, b, c, d) {
		if (a.constructor != MovieClip) {
			trace('大错  ');
			return;
		}
		//var dd=_root.getNextHighestDepth();                    
		//_root.createEmptyMovieClip('')
		a.onEnterFrame = Delegate.create(this, function () {
			a.prevFrame();
			if (a._currentframe == 1) {
				delete a.onEnterFrame;
				c.onComplete();
			}
		});
	}
}

	 